package team.yidong.fenda.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import team.yidong.fenda.entity.Guahao;
import team.yidong.fenda.entity.GuahaoHistory;

import java.util.List;

/**
 * Created by xuanlong on 2018/3/17.
 */
@Repository
public interface GuaHaoRepository extends JpaRepository<Guahao, Integer>, JpaSpecificationExecutor<Guahao> {
    @Query("select sum(guahao.guahaoNum) from Guahao guahao where guahao.hospitalDepartmentId=?1 and guahao.ghDate between ?2 and ?3 order by guahao.ghDate ASC ")
    Integer findGuahaoNum(Integer hospitalDepartmentId, String date1, String date2);

    @Query("select  guahao from  Guahao guahao where  guahao.ghDate between ?1 and ?2 and  guahao.masterId in ?3 and guahao.hospitalDepartmentId=?4 and guahao.guahaoNum<>0")
    List<Guahao> findGuahaoMaster(String date1, String date2, List<Integer> masterIdList, Integer departmentId);

    @Query("select sum(guahao.guahaoNum) from Guahao guahao where guahao.masterId=?1 and guahao.ghDate between ?2 and ?3 order by guahao.ghDate ASC ")
    Integer sumMasterGuahaoOneDayNum(Integer masterId, String date1, String date2);

    @Query("select  guahao from  Guahao guahao where  guahao.ghDate between ?1 and ?2 and guahao.hospitalDepartmentId=?3")
    List<Guahao> findGuahaoMasterForSys(String date1, String date2, Integer departmentId);

    Guahao findByGhDateAndMasterId(String guahaoDate, Integer masterId);

    List<Guahao> findByHospitalDepartmentId(Integer departmentId);
}